﻿using System;
using System.IO;
using System.Data;
using System.Windows;
using System.Collections;
using System.Windows.Input;
using System.ComponentModel;
using System.Windows.Controls;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Controls;
using Sinacor.Infra.UI.Controls.SmartClient;
using System.Collections.Generic;
using Sinacor.Infra.UI.Controls.SmartClient.Validation;
using Sinacor.UI.Bovespa.Alocacao.Presenter;
namespace Sinacor.UI.Bovespa.Alocacao.View.SmartClient
{
    public partial class ConsultaNegociosAnulados : SinacorWindow,INegocioAnulado
    {
        # region Campos
        Sinacor.UI.Bovespa.Alocacao.Presenter.NegocioAnulado _presenter;
        #endregion        
        
        #region Construtor

        public ConsultaNegociosAnulados()
        {
            this.InitializeComponent();
            dtgNegociosAnulados.NewItemType = typeof(Model.NegocioAnulado);
            this.AfterInitialize += new RoutedEventHandler(ConsultaNegociosAnulados_AfterInitialize);
        }

        #endregion

        #region INegocioAnulado Members

        public void AtualizarGridNegociosAnulados()
        {
            dtgNegociosAnulados.UpdateTarget(SinacorDataGrid.ItemsSourceProperty);
        }

        public void AtualizarComboDataPregao()
        {
            cmbDataPregao.UpdateTarget(SinacorComboBox.ItemsSourceProperty);
            cmbDataPregao.Items.SortDescriptions.Add(new SortDescription("DataPregaoFormatada", ListSortDirection.Descending));
            cmbDataPregao.SelectedIndex = 0;
        }


        /// <summary>
        /// Informa pesquisa sem resultado.
        /// </summary>
        public void InformarNenhumRegistroEncontrado()
        {
            SinacorMessageBox.Show(FindResource("Bovespa.Alocacao.Message.PesquisaSemRetorno").ToString(), SinacorMessageBoxImage.Information);
        }

        # endregion

        # region Metodos de Evento

        protected void ConsultaNegociosAnulados_AfterInitialize(object sender, RoutedEventArgs e)
        {
            this.ShowUserWaitingProcess();          
            
            _presenter = new Presenter.NegocioAnulado(this);
            _presenter.ListaDataPregao = new ModelCollection<Sinacor.UI.Bovespa.Alocacao.Model.Calendario>();
            _presenter.ListaNegociosAnulados = new ModelCollection<Sinacor.UI.Bovespa.Alocacao.Model.NegocioAnulado>();
            _presenter.FiltroNegocioAnulado = new Sinacor.UI.Bovespa.Alocacao.Model.Parameter.FiltroNegocioAnulado();
            this.DataContext = _presenter;
            _presenter.Inicializar();
            
            this.HideUserWaitingProcess();
        }
        
        # endregion


        private void btnPesquisar_Click(object sender, RoutedEventArgs e)
        {
            this.ShowUserWaitingProcess();
            _presenter.ConsultarNegociosAnulados();
            this.HideUserWaitingProcess();

        }

        private void btnNovaPesquisa_Click(object sender, RoutedEventArgs e)
        {
            this.ShowUserWaitingProcess();
            cmbDataPregao.SelectedIndex = 0;
            this._presenter.ListaNegociosAnulados.Clear();
            AtualizarGridNegociosAnulados();
            this.HideUserWaitingProcess();
        }

    }
}